<html>
<head>
  <title>Evernote Export</title>
  <basefont face="微软雅黑" size="2" />
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  <meta name="exporter-version" content="YXBJ Windows/601568 (zh-CN, DDL); Windows/10.0.0 (Win64); EDAMVersion=V2;"/>
  <style>
    body, td {
      font-family: 微软雅黑;
      font-size: 10pt;
    }
  </style>
</head>
<body>
<a name="468"/>
<h1>16-面向对象、原型、this</h1>
<div>
<table bgcolor="#D4DDE5" border="0">
<tr><td><b>创建时间：</b></td><td><i>2018/5/8 9:52</i></td></tr>
<tr><td><b>更新时间：</b></td><td><i>2020/4/13 18:04</i></td></tr>
<tr><td><b>作者：</b></td><td><i>18081003141@163.com</i></td></tr>
</table>
</div>
<br/>

<div>
<span><div><span style="font-size: 12pt;">什么是面向对象？</span></div><div><br clear="none"/></div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.15);-en-codeblock:true;"><div><span style="font-size: 12pt;">var car = {</span></div><div><span style="font-size: 12pt;">    color:&quot;white&quot;,</span></div><div><span style="font-size: 12pt;">    wheel:2</span></div><div><span style="font-size: 12pt;">}</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">var car = new Object();</span></div><div><span style="font-size: 12pt;">car.color = &quot;whilte&quot;;</span></div><div><span style="font-size: 12pt;">car.wheel = 2;</span></div></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">对象的本质：</span></div><div><span style="font-size: 12pt;">    属性和方法的集合</span></div><div><br clear="none"/></div><div><span style="font-size: 16px;">学过的对象</span></div><div><span style="font-size: 16px;">    Array、String、Math、Date .......</span></div><div><br clear="none"/></div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.15);-en-codeblock:true;"><div><span style="font-size: 16px;">var arr = [];</span></div><div><span style="font-size: 16px;">var str = &quot;Hello World&quot;;</span></div></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">结论：万事万物皆为对象</span></div><div><br clear="none"/></div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.15);-en-codeblock:true;"><div><span style="font-size: 12pt; font-family: Monaco; color: #333333;">var huahua = {</span></div><div><span style="font-size: 12pt; font-family: Monaco; color: #333333;">    height:150,</span></div><div><span style="font-size: 12pt; font-family: Monaco; color: #333333;">    manage: function(){</span></div><div><span style="font-size: 12pt; font-family: Monaco; color: #333333;">        ......</span></div><div><span style="font-size: 12pt; font-family: Monaco; color: #333333;">    }</span></div><div><span style="font-size: 12pt; font-family: Monaco; color: #333333;">}</span></div><div><span style="font-size: 12pt; font-family: Monaco; color: #333333;">huahua.manage();</span></div><div><span style="font-size: 12pt; font-family: Monaco; color: #333333;">console.log(huahua.height);</span></div></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 12pt;"><span style="font-size: 12pt; font-weight: bold;">创建对象的方式：</span></span></div><div><span style="font-size: 12pt;">    1、字面量  var obj = {}</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">    2、通过new运算符 var obj = new Object()</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">    3、构造函数</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">            用来构造（创建）对象的函数</span></div><div><span style="font-size: 12pt;">            他在声明的时候跟普通函数没有区别</span></div><div><span style="font-size: 12pt;">            用new运算符加上函数的调用，调用的结果就是一个对象</span></div><div><span style="font-size: 12pt;">  </span> <span style="font-size: 12pt;">         构造函数中的this指的是即将要new的那个对象</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">    4、ES6语法糖</span></div><div><span style="font-size: 12pt;"><br/></span></div><div><span style="font-size: 12pt; font-weight: bold;">原型</span></div><div><div><br clear="none"/></div><div><span style="font-size: 12pt;">原型是函数的伴生体</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">    我们创建的每个函数都有一个prototype(原型)属性，这个属性是一个指针，指向一个对象，而这个对象的用途是包含可以由特定类型的所有实例共享的属性和方法</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">prototype（原型）属性指向的对象就是原型对象</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">js中万物皆对象，因此原型也是对象，可以通过原型实现对象属性的继承</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">几个必记的属性和方法</span></div><ul><li><div><span style="font-size: 12pt;">constructor    prototype里面的constructor指向当前对象的构造函数</span></div></li><li><div><span style="font-size: 12pt;">__proto__   ===  [[prototype]]   指向类的prototype</span></div></li><li><div><span style="font-size: 12pt;">prototype      指向当前对象的原型对象</span></div></li><li><div><span style="font-size: 12pt;">instanceof     运算符，判断当前对象是否是另一个对象的实例</span></div></li><li><div><span style="font-size: 12pt;">hasOwnProperty  判断对象上是否存在某个属性，并且这个方法会过滤到原型上的属性</span></div></li><li><div><span style="font-size: 12pt;">isPrototypeOf      检查一个对象是否存在于另一个对象的原型链上</span></div></li></ul></div><div><br clear="none"/></div><div><br/></div><div><br clear="none"/></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 16px;">1.改写面向对象程序，要让所有函数不能嵌套；</span></div><div><br clear="none" style="font-size: 12pt;"/></div><div><span style="font-size: 16px;">2.提取变量，让函数正常运行；</span></div><div><br clear="none" style="font-size: 12pt;"/></div><div><span style="font-size: 16px;">3.改写面向对象，将方法写在prototype上；</span></div><div><br clear="none" style="font-size: 12pt;"/></div><div><span style="font-size: 16px;">4.注意this指向问题。</span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 12pt; font-weight: bold;">对象的三大特点</span></div><div><span style="font-size: 12pt; font-weight: bold;">    封装、继承、多态</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">抽象：抽出和问题相关的东西</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt; color: rgb(45, 79, 201);">封装：</span></div><div><span style="font-size: 12pt;">    1、写对象</span></div><div><span style="font-size: 12pt;">    2、用对象</span></div><div><br clear="none"/></div><div><span style="font-size: 16px;">把一些相关的对象和属性放到一起，用一个变量抽象出来，那么这就完成了这个对象的封装</span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 12pt; color: rgb(45, 79, 201);">继承：</span></div><div><span style="font-size: 12pt; color: rgb(45, 79, 201);">   </span><span style="font-size: 12pt;"> 子承父业</span></div><div><span style="font-size: 12pt;">    子对象可以使用父对象的一些属性和方法</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt; color: rgb(45, 79, 201);">多态：重载，重写</span></div><div><span style="font-size: 12pt;">    重载就是根据不同的参数类型，参数个数实现不同的功能</span></div><div><span style="font-size: 12pt;">    重写就是父类的方法不好用，我自己重新定义一个方法名相同的不同方法</span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 16pt;"><span style="font-size: 16pt; font-weight: bold;">this</span></span></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">this是js的关键字</span></div><div><span style="font-size: 12pt;">   他是根据执行上下文（执行环境）动态指向当前调用的对象；</span></div><div><span style="font-size: 12pt;">   谁调用，就指谁；</span></div><div><font style="font-size: 12pt;"><br clear="none"/></font></div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.15);-en-codeblock:true;"><div><font color="#000000" style="font-size: 12pt;"><span style="min-height: 17pt; font-family: consolas;">var</span> <span style="min-height: 17pt; font-family: consolas;">a</span><span style="min-height: 17pt; font-family: consolas;">=</span><span style="min-height: 17pt; font-family: consolas;">2</span><span style="min-height: 17pt; font-family: consolas;">;</span></font></div><div style="min-height: 17pt;"><font color="#000000" style="font-size: 12pt;"><span style="min-height: 17pt; font-family: consolas;">function</span><span style="min-height: 17pt;"> </span><span style="min-height: 17pt; font-family: consolas;">fun</span><span style="min-height: 17pt; font-family: consolas;">(){</span></font></div><div style="min-height: 17pt;"><font color="#000000" style="font-size: 12pt;"><span style="min-height: 17pt; font-family: consolas;">    console</span><span style="min-height: 17pt; font-family: consolas;">.log(</span><span style="min-height: 17pt; font-family: consolas;">this</span><span style="min-height: 17pt; font-family: consolas;">.a);</span></font></div><div style="min-height: 17pt;"><span style="min-height: 17pt; font-family: consolas;"><font color="#000000" style="font-size: 12pt;">}</font></span></div><div style="min-height: 17pt;"><font color="#000000" style="font-size: 12pt;"><span style="min-height: 17pt; font-family: consolas;">var</span><span style="min-height: 17pt;"> </span><span style="min-height: 17pt; font-family: consolas;">o</span><span style="min-height: 17pt; font-family: consolas;">=</span><span style="min-height: 17pt; font-family: consolas;">{a</span><span style="min-height: 17pt; font-family: consolas;">:</span><span style="min-height: 17pt; font-family: consolas;">3</span><span style="min-height: 17pt; font-family: consolas;">,fun</span><span style="min-height: 17pt; font-family: consolas;">:</span><span style="min-height: 17pt; font-family: consolas;">fun}</span></font></div><div style="min-height: 17pt;"><font color="#000000" style="font-size: 12pt;"><span style="min-height: 17pt; font-family: consolas;">var</span><span style="min-height: 17pt;"> </span><span style="min-height: 17pt; font-family: consolas;">p</span><span style="min-height: 17pt; font-family: consolas;">=</span><span style="min-height: 17pt; font-family: consolas;">{a</span><span style="min-height: 17pt; font-family: consolas;">:</span><span style="min-height: 17pt; font-family: consolas;">4</span><span style="min-height: 17pt; font-family: consolas;">};</span></font></div><div style="min-height: 17pt;"><span style="min-height: 17pt; font-family: consolas;"><font color="#000000" style="font-size: 12pt;">o.fun(); </font></span></div><div style="min-height: 17pt;"><font color="#000000" style="font-size: 12pt;"><span style="min-height: 17pt; font-family: consolas;">(p.fun</span><span style="min-height: 17pt; font-family: consolas;">=</span><span style="min-height: 17pt; font-family: consolas;">o.fun)();</span></font></div></div><div><br clear="none"/></div><div><br clear="none"/></div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.15);-en-codeblock:true;"><div><span style="font-family: Monaco; color: #333333;"><span style="font-size: 12pt;">var object = {</span></span></div><div><span style="font-family: Monaco; color: #333333;"><span style="font-size: 12pt;">    //getName是Object的方法</span></span></div><div><span style="font-family: Monaco; color: #333333;"><span style="font-size: 12pt;">    getName : function(){</span></span></div><div><span style="font-family: Monaco; color: #333333;"><span style="font-size: 12pt;">    //x是getName里面的函数，它是作为函数调用的，this就是window啦</span></span></div><div><span style="font-family: Monaco; color: #333333;"><span style="font-size: 12pt;">        function x(){</span></span></div><div><span style="font-family: Monaco; color: #333333;"><span style="font-size: 12pt;">            console.log(this);</span></span></div><div><span style="font-family: Monaco; color: #333333;"><span style="font-size: 12pt;">        }</span></span></div><div><span style="font-family: Monaco; color: #333333;"><span style="font-size: 12pt;">        x();</span></span></div><div><span style="font-family: Monaco; color: #333333;"><span style="font-size: 12pt;">    }</span></span></div><div><span style="font-family: Monaco; color: #333333;"><span style="font-size: 12pt;">}</span></span></div><div><span style="font-family: Monaco; color: #333333;"><span style="font-size: 12pt;">object.getName(); //window</span></span></div></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 12pt;">call()、apply()、bind()  可以改变this的指向</span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 16pt;">OOA、OOD、OOP</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><img src="00-笔记_files/你办事我放心.png" type="image/png" data-filename="你办事我放心.png" style="font-family: Helvetica; font-size: 11pt; color: #333333;" width="518"/></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 21px; font-family: &quot;Yu Gothic UI&quot;;">OOA面向对象分析</span><span style="letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(245, 245, 245); font-size: 16pt; color: rgb(51, 51, 51); font-family: Helvetica, Tahoma, Arial, sans-serif; font-variant-caps: normal; font-variant-ligatures: normal;">（Object-Oriented Analysis）</span><span style="font-size: 21px; font-family: &quot;Yu Gothic UI&quot;;">:</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(245, 245, 245); font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;">毛泽东向华国锋同志说，你办事我放心</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="background-color: rgb(245, 245, 245); font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;">华国锋一个人就把事办完了？</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="background-color: rgb(245, 245, 245); font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;">华国锋开始分配任务了，他向其他人说：你办事我放心</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="background-color: rgb(245, 245, 245); font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;">司令：</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="background-color: rgb(245, 245, 245); font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;">财政部：</span></div><div><span style="font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;">......</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="background-color: rgb(245, 245, 245); font-size: 14pt; color: rgb(45, 79, 201); font-family: &quot;Yu Gothic UI&quot;;">分工：通过分工，团队配合，完成大型工作</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;">分析问题，将问题抽象化，对团队里每个部分进行归类分析</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;">军事：司令 --&gt; 作战，装备，后勤（精密协作）</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;">          司令 --&gt; 军长 --&gt; 师长 ......   （从整体到局部）</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">面向对象分析:</span> <span style="font-size: 16px; color: rgb(255, 0, 0); font-family: &quot;Yu Gothic UI&quot;; font-weight: bold;">将大问题拆分成小问题，并试图用分工协作</span><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">来完成 的思维方式。</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">    面向对象不是编程独有思维方式。</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 14px; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(245, 245, 245); color: rgb(51, 51, 51); font-family: Helvetica, Tahoma, Arial, sans-serif; font-variant-caps: normal; font-variant-ligatures: normal;">面向对象分析方法（Object-Oriented Analysis，OOA），是在一个系统的开发过程中进行了系统业务调查以后，按照面向对象的思想来分析问题。OOA与结构化分析有较大的区别。OOA所强调的是在系统调查资料的基础上，针对OO方法所需要的素材进行的归类分析和整理，而不是对管理业务现状和方法的分析。</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 14px; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(245, 245, 245); color: rgb(51, 51, 51); font-family: Helvetica, Tahoma, Arial, sans-serif; font-variant-caps: normal; font-variant-ligatures: normal;">OOA（面向对象的分析）模型由5个层次（主题层、对象类层、结构层、属性层和服务层）和5个活动（标识对象类、标识结构、定义主题、定义属性和定义服务）组成。在这种方法中定义了两种对象类之间的结构，一种称为分类结构，一种称为组装结构。分类结构就是所谓的一般与特殊的关系。组装结构则反映了对象之间的整体与部分的关系。</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 16pt; font-family: &quot;Yu Gothic UI&quot;;">OOD面向对象设计</span><span style="letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(245, 245, 245); font-size: 16pt; color: rgb(51, 51, 51); font-family: Helvetica, Tahoma, Arial, sans-serif; font-variant-caps: normal; font-variant-ligatures: normal;">（Object-Oriented Design）</span><span style="font-size: 16pt; font-family: &quot;Yu Gothic UI&quot;;">:</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 24px; font-family: &quot;Yu Gothic UI&quot;; font-weight: bold;"> </span> <span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;; font-weight: bold;">  1.分析模块后，确定职责。</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">          以战争为例：</span><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;"> </span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">          </span><span style="font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;">作战 --&gt; 军事领导</span></div><div><span style="font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;">          装备 --&gt; 武器专家</span></div><div><span style="font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;">          后勤 --&gt; 炊事班，医疗队</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">      </span></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;; font-weight: bold;">     2.确定耦合关系。</span></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">          </span></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">        确定通讯关系，如何交流（设计阶段）</span></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">        模块与模块之间的互相关系（</span><span style="font-size: 16px; color: rgb(45, 79, 201); font-family: &quot;Yu Gothic UI&quot;;">高内聚，低耦合</span><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">）   </span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;; font-weight: bold;">     3.为OOP做准备。</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="box-sizing: border-box; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 16pt; color: rgb(0, 0, 0); font-family: 微软雅黑; font-variant-caps: normal; font-variant-ligatures: normal;">OOP面向对象编程</span><span style="box-sizing: border-box; font-size: 16pt; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(245, 245, 245); color: rgb(51, 51, 51); font-family: Helvetica, Tahoma, Arial, sans-serif; font-variant-caps: normal; font-variant-ligatures: normal;">（Object-Oriented Programming）</span><span style="box-sizing: border-box; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 16pt; color: rgb(0, 0, 0); font-family: 微软雅黑; font-variant-caps: normal; font-variant-ligatures: normal;">:</span></div><div><span style="font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;">        </span></div><div><span style="font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;">    </span><span style="font-size: 24px; font-family: &quot;Yu Gothic UI&quot;;"> </span><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">分析角色特性  --&gt;  </span></div><div><br clear="none" style="font-size: 12pt; font-family: Yu Gothic UI;"/></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">                    士兵  --&gt;  作战勇猛 (附加属性);</span></div><div><br clear="none" style="font-size: 12pt; font-family: Yu Gothic UI;"/></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">                             --&gt; 使用武器装备打击敌人 (技能)</span></div><div><br clear="none" style="font-size: 12pt; font-family: Yu Gothic UI;"/></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">                    狙击手  --&gt;  狙击能力出众;</span></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">          </span></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">          找到角色间的共同性。 </span></div><div><br clear="none" style="font-size: 12pt; font-family: Yu Gothic UI;"/></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">                    狙击手</span> <span style="font-size: 16px; color: rgb(45, 79, 201); font-family: &quot;Yu Gothic UI&quot;;">继承</span><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">于 士兵</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">         </span> <span style="font-size: 16px; color: rgb(45, 79, 201); font-family: &quot;Yu Gothic UI&quot;;">思考方式  &gt;  </span><span style="font-size: 16px; color: rgb(45, 79, 201); font-family: &quot;Yu Gothic UI&quot;;">语法;</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;; font-weight: bold;">如何面向对象？</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">    将内容包含在对象中  --&gt; 信息传递速度更快 ，效率更高。 </span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">    大量信息加工困难， 需要打包。</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">    系统升级 --&gt; 通过增加和删除组件实现需求 。（某个软件中的组件）</span></div><div><span style="font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;">        </span></div><div><span style="font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;">    优点在于分工合作，同时发生（有些事是没有先后顺序关系的），方便升级维护</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">    程序设计:</span></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">    function Soilder(name){</span></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">        this.name = name;</span></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">    }</span></div><div><span style="font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;">    Soilder</span><span style="font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;">.prototype = {</span></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">        射击能力:function () {</span></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">            ...</span></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">       }</span></div><div><span style="font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;">        ......</span></div><div><span style="font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;">      }</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">    功能实现:</span></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">       new Soilder</span><span style="font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;"> </span><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">(&quot;董存瑞&quot;);</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">       new </span> <span style="font-size: 12pt; font-family: &quot;Yu Gothic UI&quot;;">Soilder </span><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">(&quot;顺溜&quot;);</span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><img src="00-笔记_files/顺溜.jpg" type="image/jpeg" data-filename="顺溜.jpg" style="font-size: 12pt; font-family: Yu Gothic UI;" width="392"/></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><span style="font-size: 16px; color: rgb(227, 0, 0); font-family: &quot;Yu Gothic UI&quot;; font-weight: bold;">   </span></div><div><span style="font-size: 16px; color: rgb(227, 0, 0); font-family: &quot;Yu Gothic UI&quot;; font-weight: bold;">    //类和对象的关系 --&gt;  模板  --&gt; 产品;</span></div><div style="margin-left: 80px;"><div style="font-size: 12pt;"><br clear="none" style="font-size: 12pt; font-family: Yu Gothic UI;"/></div></div><div><span style="font-size: 16px; font-family: &quot;Yu Gothic UI&quot;;">    定义好模板之后， 产出产品那么产品功能必然类似。 </span></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><br clear="none" style="font-family: Yu Gothic UI; font-size: 12pt;"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div></span>
</div></body></html> 